package com.zmm.zebulon.module.trade.biz.controller.app.config;

import cn.hutool.core.util.ObjUtil;
import com.zmm.zebulon.common.pojo.CommonResult;
import com.zmm.zebulon.module.trade.biz.convert.config.TradeConfigConvert;
import com.zmm.zebulon.module.trade.biz.dal.dataobject.config.TradeConfigDO;
import com.zmm.zebulon.module.trade.biz.dal.vo.config.AppTradeConfigRespVO;
import com.zmm.zebulon.module.trade.biz.service.config.TradeConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

/**
 * description: TODO
 *
 * @author zebulon
 * package com.zmm.zebulon.module.trade.biz.controller.app.config
 * name: AppTradeConfigController
 * date 2025/9/4 20:16
 */
@Tag(name = "用户 App - 交易配置")
@RestController
@RequestMapping("/trade/config")
@RequiredArgsConstructor
@Validated
@Slf4j
public class AppTradeConfigController {

    @Resource
    private TradeConfigService tradeConfigService;

    @Value("${zebulon.tencent-lbs-key}")
    private String tencentLbsKey;

    @GetMapping("/get")
    @Operation(summary = "获得交易配置")
    @PermitAll
    public CommonResult<AppTradeConfigRespVO> getTradeConfig() {
        TradeConfigDO config = ObjUtil.defaultIfNull(tradeConfigService.getTradeConfig(), new TradeConfigDO());
        return CommonResult.success(TradeConfigConvert.INSTANCE.convert02(config).setTencentLbsKey(tencentLbsKey));
    }

}
